package cn.itcast.travel.service.impl;

import cn.itcast.travel.domain.blogtype;
import cn.itcast.travel.service.BlogtypeService;
import cn.itcast.travel.util.JDBCUtils;
import cn.itcast.travel.web.servlet.blogtype.Blogtype;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class BlogtypeServiceImpl implements BlogtypeService {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    //获取所有博客分类
    @Override
    public List<blogtype> getalltype() {
        List<blogtype> bt=null;
        String sql="select * from t_blogtype";
        try{
            bt=template.query(sql,new BeanPropertyRowMapper<blogtype>(blogtype.class));
        }catch (Exception e){

        }
        return bt;
    }

    //添加博客类别
    @Override
    public void addtype(blogtype b) {
        String sql="insert into t_blogtype(typeName) value(?)";
        template.update(sql,b.getTypeName());
    }
}
